package com.work.cos.service.impl.pr;

import java.util.List;

import org.springframework.stereotype.Service;

import com.work.cos.domain.entity.pr.PrOrderDetailEntity;
import com.work.cos.domain.entity.pr.PrOrderEntity;
import com.work.cos.domain.entity.pr.PrOrderEntity.ORDER_STATUS;
import com.work.cos.mapper.pr.PrOrderMapper;
import com.work.cos.service.impl.BaseServiceImpl;
import com.work.cos.service.interfc.pr.IPrOrderService;

@Service
public class PrOrderServiceImpl  extends BaseServiceImpl<PrOrderMapper, PrOrderEntity> implements IPrOrderService{

	@Override
	public List<PrOrderEntity> getListByOrderStatus(Integer orderStatus, Long userId) {
		return baseMapper.getListByOrderStatus(orderStatus, userId);
	}
	
	@Override
	public PrOrderEntity getListByUserIdAndId(String userId, Long id) {
		return baseMapper.getListByUserIdAndId(userId, id);
	}

	@Override
	public boolean toStatusUpdate(Integer orderStatus, String userId, Long id) {
		PrOrderEntity entity = this.getListByUserIdAndId(userId, id);
		if(null != entity && orderStatus > entity.getOrderStatus()){
			
			return baseMapper.toStatusUpdate(orderStatus, userId, id) > 0;
		}
		return false;
	}

	@Override
	public boolean toStatusCancel(Integer isCancel, String userId, Long id) {
		return baseMapper.toStatusCancel(isCancel, userId, id) > 0;
	}

	@Override
	public boolean add(List<PrOrderDetailEntity> list) {
		//存储明细表
		
		//生成订单主表
		PrOrderEntity orderEntity= new PrOrderEntity();		
		orderEntity.setUserName(userName);
		orderEntity.setMobile(mobile);
		orderEntity.setAddress(address);
		orderEntity.setOrderStatus(PrOrderEntity.ORDER_STATUS.WAIT_PAY.getCode());
		return false;
	}
}
